<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <style>
        .container{
            padding-top: 150px;
        }
        .padding{
            padding: 5px 0 20px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="form-group">
            <label>请选择文件</label>
            <input type="file" id="file">
        </div>
    </div>
    <script>
        var file = document.getElementById('file');
        file.onchange = function(){
            //创建空表单对象
            var formData = new FormData();
            //将用户选择的二进制文件追加到表单对象中
            formData.append('attrName',this.files[0]);
            var xhr = new XMLHttpRequest();
            //配置ajax对象
            xhr.open('post','http://localhost:3000/upload');
            xhr.send(formData);
            xhr.onload= function(){
                if(xhr.status ==200){
                    console.log(xhr.responseText);
                }
            }
        }
    </script>
</body>
</html>